package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.RecipeDAO;
import DTO.RecipeDTO;
import VMO.DishVMO;
import XMLUtilities.StAXUtilities;

/**
 * Servlet implementation class RecipeDetailClientServlet
 */
public class RecipeDetailClientServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RecipeDetailClientServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String recipeId_str = request.getParameter("id");
		
		String realPath = getServletContext().getRealPath("/");
		String xmlFilePath = realPath + "WEB-INF/xml/recipe-detail.xml";

		ArrayList<DishVMO> dishList = new ArrayList<DishVMO>();
		dishList = StAXUtilities.findDishInRecipe(xmlFilePath, Integer.parseInt(recipeId_str));

		RecipeDAO recipeDAO = new RecipeDAO();
		RecipeDTO recipeDTO = new RecipeDTO(Integer.parseInt(recipeId_str), "");
		recipeDAO.get(recipeDTO);
		request.setAttribute("RECIPEDTO", recipeDTO);
		request.setAttribute("DISHLIST", dishList);
		RequestDispatcher rd = request.getRequestDispatcher("recipe-details.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
